<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:RpcController.php,2010/05/28 14:39:00 
 * 
 **************************************************************************/
 
 
 
/**
 * @file RpcController.php
 * @author huqingping(huqingping@)
 * @date 2010/05/28 14:39:00
 * @version 1.0 
 * @brief 
 *  
 **/
class RpcController extends PageController
{
	function index($method)
	{
		$try = intval($this->get('_try',1));
		if ($try <= 0) {
			$try = 1;
		}
		if ($try > Conf::get('hapn.rpctry',3)) {
			//默认最大尝试3次
			throw new Exception("hapn.rpccall recursion");
		}
		list($mod,$method) = explode('.',$method);
		if (!$mod || !$method) {
			throw new Exception('hapn.errrpccall');
		}
		$args = $this->request->get('rpcinput');
		$params = $this->request->get('rpcinit');
		//为了支持多级模块，把:转换成/，因为掉会用时把/当作:传入
		$mod = str_replace(':','/',$mod);
		$params["_try"] = $try;
		$proxy = ApiProxy::getProxy($mod,$params);
		$ret = call_user_func_array(array($proxy,$method),$args);
		$this->set('rpcret',$ret);
	}
}






/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
